package phoenix.mob_android.test_objects;

import phoenix.core.PhoenixManager;
import phoenix.core.base.extensions.TestBaseMobAndroidExt;
import phoenix.core.data_models.UserProfileDataModel.PaymentDetails;
import phoenix.mob_android.test_objects.data_providers.PaymentDataProviders;

public class PaymentTests extends TestBaseMobAndroidExt
{
	public PaymentTests(PhoenixManager p_phoenix)
	{
		super(p_phoenix);
	}

	// Data
	public PaymentDataProviders dataProviders = new PaymentDataProviders(manager);

	public void paymentTest(Integer p_membershipPackage, PaymentDetails p_paymentDataParams, boolean p_expected)
	{
		try
		{

			page().mainMenu().openMainMenu().clickUpgradeButton();
			page().paymentPage().isOnPaymentPage();
			md().wait(5);
			if (page().paymentPage().checkForLoadingIcon())
			{
				page().mainMenu().openMainMenu().clickUpgradeButton();
				md().wait(10);
			}
			page().paymentPage().selectMembership(p_membershipPackage).fillPaymentDetails(p_paymentDataParams,
					p_expected);

			if (page().featuresPage().isOnFeatureSelectionPage() && p_expected)
			{
				testUser().setMembershipStatus(1);
				db().updateUserData(testUser());
			}
			else
			{
				log().errorAndScreen("Error: not on Feature selection page after success payment");
			}

		}
		catch (Exception p_ex)
		{
			log().errorAndScreen("Payment test error " + p_ex.toString());
		}

		// Verifying result
		test().forErrors();
	}

	public void featuresTest()
	{
		try
		{
			page().mainMenu().openMainMenu().clickFeaturesBanner();
			page().featuresPage().isOnFeatureSelectionPage();
			if (page().paymentPage().checkForLoadingIcon())
			{
				page().mainMenu().openMainMenu().clickFeaturesBanner();
				md().wait(5);
			}
			page().featuresPage().submitFeatures();
			md().wait(5);
			page().indexPage().clickBackAndroidButton();
			if (!page().mainMenu().openMainMenu().isFeatureBunnerVisible())
			{
				testUser().setMembershipStatus(4);
				db().updateUserData(testUser());
			}
			else
			{
				log().errorAndScreen("Error: upgrade bunner is visible after buying features package");
			}
		}
		catch (Exception p_ex)
		{
			log().errorAndScreen("Features test error " + p_ex.toString());
		}

		// Verifying result
		test().forErrors();
	}
}
